<?php
class multitender_action_userbar extends multitender_action {

    function run() {
        $tpl = $this->new_tpl();
        $um = $this->new_model('users');
        $user_id = $um->get_user_id();
        unset($um);
        $tpl->assign('user_id', $user_id);
        if ($user_id) {
            $tpl->assign('username', $this->conf['user']['name']);
            $card_user = $this->new_model('card_user');
            $user = $card_user->get_access($user_id);
            if ($user['todate'] > date('Y-m-d')) {
                $tpl->assign('todate', Ceil( (strtotime($user['todate']) - time()) / (60*60*24) ));
            }
            if ($user['tenders'] > 0) {
                $tpl->assign('tenders', $user['tenders']);
            }
            $tpl->assign('rights', $this->conf['user']['right']);
        }
        
        if (preg_match("#MSIE 6#sui", $_SERVER['HTTP_USER_AGENT'])) {
            $tpl->assign('message', 1);
        } else {
            $tpl->assign('message', 0);
        }
        
        if (isset($_COOKIE['TC_ALERT_LOGIN'])) {
            $user_id = (int) $_COOKIE['TC_ALERT_LOGIN'];
            $users = $this->new_model('users');
            $users = $users->get_user_by_ids(array($user_id));
            $user = $users[0];
            $tpl->assign('alert_user', $user);
        }

        return $tpl->fetch('userbar.tpl');
    }
}